<?php

require_once('functions/pageLoad.php');


if(isset($_GET['date']) && isset($_GET['url'])){

	$sql = "SELECT article_title, article_date, article_content FROM blog WHERE article_date = '".mysql_real_escape_string($_GET['date'])."' AND article_url = '".mysql_real_escape_string($_GET['url'])."'";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());
	$rs=mysql_fetch_assoc($query);

$page_title = $rs['article_title'].' - Blog';
$content = '<h1>'.$rs['article_title'].'</h1><span class="article_date">'.date("d/m/Y", strtotime($rs['article_date'])).'</span><a href="/blog" class="blog_back_button">Back to blog</a><div style="float: left; width: 100%;">'.$rs['article_content'].'</div>';

}

else{

$page_title = 'Blog';

	$sql = "SELECT article_title, article_date, article_content, article_url FROM blog ORDER BY article_date DESC";
	$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());
	
	$content='<h1>Blog</h1>';
	
	while($rs=mysql_fetch_assoc($query)){
	
	$excerpt = substr(strip_tags($rs['article_content']), 0, 200);
	
	$content.='<div class="blog_post">
		<h2><a href="/blog/'.$rs['article_date'].'/'.$rs['article_url'].'">'.$rs['article_title'].'</a></h2>
		<span class="blog_post_date">'.date("d/m/Y", strtotime($rs['article_date'])).'</span>
		<p>'.$excerpt.'...</p>
	</div>';
	
	}


}

include('includes/meta.php');
include('includes/header.php');
include('includes/navigation.php');

?>

<?php echo $content; ?>

<?php 

include('includes/rightColumn.php');
include('includes/footer.php');

?>